class Solution {
    fun maxProfit(prices: IntArray): Int {
        var count = 0;
        for (i in 0..(prices.size - 2)){
            val tmp = prices[i + 1] - prices[i];
            count += if (tmp > 0) tmp else 0;
        }
        return count;
    }
}

val s = Solution();
println(s.maxProfit(intArrayOf(1, 2, 3, 4)));
